// SkinDetection.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "vector"
#include "math.h"
#include "cv.h"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
using namespace cv;

#include "iostream"
using namespace std;

void readAVI(std::string path);
int readCamera();
void skinDetection(std::string path);

int _tmain(int argc, _TCHAR* argv[])
{
	Mat scr = imread("E:/Test/skin_detect_1.jpg");
	
	if(scr.empty()){
		printf("Khong tim thay hinh anh");
		cout <<"thuy";
		return -1;
	}


	/*
	 *HVS MODE 1
	 *
	 */
	Mat HVS;
	cvtColor(scr, HVS, CV_BGR2HSV);

	Mat HVS_skin;
	inRange(HVS, Scalar(0, 58, 89), Scalar(25, 173, 229), HVS_skin);
	Mat dich;
	imshow("SCR",scr);
	imshow("HVS MODE",HVS_skin);


	Mat Y;
	cvtColor(scr, Y, CV_BGR2YCrCb);
	Mat Y_skin;
	inRange(Y, Scalar(80, 135, 85), Scalar(254, 180, 135), Y_skin);
	imshow("YCrCb",Y_skin);

	waitKey(0);

	return 0;
}

void readAVI(std::string path){
	Mat frame;
    VideoCapture capture(path); 
    namedWindow("my_window");
	bool ok = capture.read( frame);
	while(ok) {
		try{
			ok = capture.read( frame);
			imshow("my_window", frame);
			if(cv::waitKey(30) >= 0) break;
		}catch(cv::Exception &ex){
			cout<<"co loi: "<<ex.err;
		}
    }

}

int readCamera(){
	VideoCapture cap(0); // open the default camera

	if(!cap.isOpened()) // check if we succeeded
		return -1;

	while(true){
		Mat frame;
		cap.read( frame); // get a new frame from camera
		try{
		imshow("cam", frame);
		}catch(cv::Exception ex){
			cout<<"co loi "<<ex.err;
		}
		if(waitKey(40) >= 0) break;
	}
}

void skinDetection(std::string path){
	
}